# src/latest_ai_development/crew.py
from crewai.project import CrewBase, agent, crew, task,before_kickoff, after_kickoff
from crewai_tools import SerperDevTool
from langchain_openai import ChatOpenAI
import os
os.environ["OPENAI_API_KEY"] = "NA"
os.environ["SERPER_API_KEY"] = "944bb7dc2e1e38c24a9d104069a4fda82f82dc323e41c9eaf655a8db7c5e1087"
llm = ChatOpenAI(
 model = "ollama/llama3.2",
 base_url = "http://localhost:11434")

@CrewBase
class OcrPdf():
  """LatestAiDevelopment crew"""
  @before_kickoff
  def before_kickoff_function(self, inputs):
    print(f"Before kickoff function with inputs: {inputs}")
    return inputs # You can return the inputs or modify them as needed

  @after_kickoff
  def after_kickoff_function(self, result):
    print(f"After kickoff function with result: {result}")
    return result # You can return the result or modify it as needed

  @agent
  def architect(self) -> Agent:
    return Agent(
      config=self.agents_config['architect'],
      verbose=True,
      llm = llm,
      tools=[SerperDevTool()]
    )

  @agent
  def developer(self) -> Agent:
    return Agent(
      config=self.agents_config['developer'],
      llm = llm,
      verbose=True
    )

  @task
  def architect_task(self) -> Task:
    return Task(
      config=self.tasks_config['architect_task'],
    )

  @task
  def developer_task(self) -> Task:
    return Task(
      config=self.tasks_config['developer_task'],
      output_file='output/res.py' # This is the file that will be contain the final report.
    )

  @crew
  def crew(self) -> Crew:
    """Creates the LatestAiDevelopment crew"""
    return Crew(
      agents=self.agents, # Automatically created by the @agent decorator
      tasks=self.tasks, # Automatically created by the @task decorator
      process=Process.sequential,
      verbose=True,
    )
